package com.laiketui.task.config;

import com.laiketui.domain.lktconst.DictionaryConst;
import com.laiketui.domain.lktconst.ErrorCode;
import com.laiketui.common.api.order.PublicTaskService;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.utils.help.SpringHelper;
import com.laiketui.task.services.dubbo.TaskServiceImpl;
import com.laiketui.task.services.dubbo.plugin.AuctionTaskServiceImpl;
import com.laiketui.task.services.dubbo.plugin.DistributionTaskServiceImpl;
import com.laiketui.task.services.dubbo.plugin.SecondsTaskSerciceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 任务工厂
 *
 * @author Trick
 * @date 2021/4/13 18:10
 */
@Component
@Deprecated
public class TaskFactory {

    @Autowired
    SpringHelper springHelper;

    public PublicTaskService getTaskService(String type) throws LaiKeAPIException {
        try {
            PublicTaskService publicTaskService;
            switch (type) {
                case DictionaryConst.OrdersType.ORDERS_HEADER_MS:
                    publicTaskService = springHelper.getBean(SecondsTaskSerciceImpl.class);
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_JP:
                    publicTaskService = springHelper.getBean(AuctionTaskServiceImpl.class);
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_FX:
                    publicTaskService = springHelper.getBean(DistributionTaskServiceImpl.class);
                    break;
                default:
                    publicTaskService = springHelper.getBean(TaskServiceImpl.class);
            }

            return publicTaskService;
        } catch (Exception e) {
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.BUSY_NETWORK, e.getMessage());
        }
    }
}
